<?php

/**
 * This is the model class for table "Product".
 *
 * The followings are the available columns in table 'Product':
 * @property integer $ProductID
 * @property string $ProductModel
 * @property string $ProductName
 * @property string $ProductDetail
 * @property string $VendorCode
 * @property string $Inventory
 * @property string $Specialty
 * @property string $SizeInch
 * @property string $Sizecm
 * @property double $WeightLB
 * @property double $WeightG
 * @property double $WeighttoCust
 * @property double $FactoryCost
 * @property double $LACost
 * @property string $Packing
 * @property integer $PurchaseTotal
 * @property integer $SalesTotal
 * @property integer $DamagedTotal
 * @property double $AverageCost
 * @property integer $OnHand
 * @property integer $ReorderPoint
 * @property string $Comment
 * @property string $CreateTime
 * @property string $UpdateTime
 * @property string $Login
 * @property string $Modifier
 * @property double $LAAvgCost
 * @property string $PModel_2
 * @property integer $UsedTotal
 * @property integer $OnHold
 * @property integer $Available
 * @property integer $ShipTotal
 * @property integer $LentTotal
 * @property string $Currency
 * @property string $Category
 * @property string $Color
 * @property string $SubCategory
 * @property string $Style
 * @property string $Type
 * @property string $Div
 * @property string $SubDiv
 * @property string $NIDNo
 * @property double $Amazon_S
 * @property double $Ebay_S
 * @property string $Class
 * @property string $Rank
 * @property integer $OnShipping
 * @property integer $TurnaroundTime
 * @property double $TurTimeCoefficient
 * @property integer $ReOrder_Qty
 * @property integer $ReOrder_Days
 * @property integer $OHDayNo
 * @property double $Ivnt_Value
 * @property integer $ExceedingNo
 * @property double $AverageProfit
 * @property integer $SalesWeek
 * @property string $NIP_Photo
 * @property string $NIP_Desc
 * @property string $NIP_Keyword
 * @property string $NIP_InstructionManu
 * @property string $NIP_Software
 * @property string $Package
 * @property string $Holiday
 * @property string $Event
 * @property string $Promotion
 * @property integer $ListingNo
 * @property string $Listing_Ready
 * @property string $Description
 * @property double $Amazon_P
 * @property double $eBayFS
 * @property double $Buy
 * @property double $Offer
 * @property double $Bid
 * @property string $Lot
 * @property double $Lot1_Amazon
 * @property double $Lot2_Amazon
 * @property double $Lot3_Amazon
 * @property double $Lot4_Amazon
 * @property string $QStatus
 * @property integer $Purchased
 * @property string $Listing_Des
 * @property string $RCMDPerson
 * @property double $Lot1_Ebay
 * @property double $Lot2_Ebay
 * @property double $Lot3_Ebay
 * @property double $Lot4_Ebay
 * @property string $Flup_P
 * @property string $OF1
 * @property string $OF2
 * @property string $FollowList
 * @property double $Freight_Home
 * @property double $Freight_ByAir
 * @property double $Freight_BySea
 * @property double $Freight_USAF
 * @property double $Freight_ToCus
 * @property double $Amazon_L
 * @property double $Ebay_L
 * @property string $Package_Code
 * @property integer $Qty_1Day
 * @property integer $Qty_3Day
 * @property integer $Qty_1Week
 * @property integer $Qty_2Week
 * @property integer $Qty_4Week
 * @property double $Qty_Avg_3Day
 * @property double $Qty_Avg_1Week
 * @property double $Qty_Avg_2Week
 * @property double $Qty_Avg_4Week
 * @property double $Qty_Avg_12Week
 * @property integer $Q_Diff_1Day
 * @property integer $Q_Diff_1Week
 * @property string $StockoutDate
 * @property double $Avg_SalesVolume
 * @property integer $TAT_StockUp_D
 * @property integer $TAT_Shipping_D
 * @property integer $TAT_Offset_D
 * @property double $ItemCoefficient
 * @property double $SeasonCoefficient
 * @property double $AdjustedSalesRate
 * @property double $Profit_C
 * @property integer $ProdPackL_cm
 * @property integer $ProdPackW_cm
 * @property integer $ProdPackH_cm
 * @property integer $BoxSizeL_cm
 * @property integer $BoxSizeW_cm
 * @property integer $BoxSizeH_cm
 * @property string $ProductSize
 * @property integer $BoxQuantity
 * @property string $Active
 */
class Product extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Product the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'Product';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('Category, SubCategory', 'required'),
            array('PurchaseTotal, SalesTotal, DamagedTotal, OnHand, ReorderPoint, UsedTotal, OnHold, Available, ShipTotal, LentTotal, OnShipping, TurnaroundTime, ReOrder_Qty, ReOrder_Days, OHDayNo, ExceedingNo, SalesWeek, ListingNo, Purchased, Qty_1Day, Qty_3Day, Qty_1Week, Qty_2Week, Qty_4Week, Q_Diff_1Day, Q_Diff_1Week, TAT_StockUp_D, TAT_Shipping_D, TAT_Offset_D, ProdPackL_cm, ProdPackW_cm, ProdPackH_cm, BoxSizeL_cm, BoxSizeW_cm, BoxSizeH_cm, BoxQuantity', 'numerical', 'integerOnly' => true),
            array('WeightLB, WeightG, WeighttoCust, FactoryCost, LACost, AverageCost, LAAvgCost, Amazon_S, Ebay_S, TurTimeCoefficient, Ivnt_Value, AverageProfit, Amazon_P, eBayFS, Buy, Offer, Bid, Lot1_Amazon, Lot2_Amazon, Lot3_Amazon, Lot4_Amazon, Lot1_Ebay, Lot2_Ebay, Lot3_Ebay, Lot4_Ebay, Freight_Home, Freight_ByAir, Freight_BySea, Freight_USAF, Freight_ToCus, Amazon_L, Ebay_L, Qty_Avg_3Day, Qty_Avg_1Week, Qty_Avg_2Week, Qty_Avg_4Week, Qty_Avg_12Week, Avg_SalesVolume, ItemCoefficient, SeasonCoefficient, AdjustedSalesRate, Profit_C', 'numerical'),
            array('ProductModel, ProductName, PModel_2, Category, Color, SubCategory, Style', 'length', 'max' => 100),
            array('ProductDetail, Packing, Comment, Description, Listing_Des, FollowList', 'length', 'max' => 1073741823),
            array('VendorCode, CreateTime, UpdateTime, Login, Modifier', 'length', 'max' => 255),
            array('Inventory, Specialty, SizeInch, Sizecm, Type, Div, SubDiv, NIDNo, Class, Rank, NIP_Photo, NIP_Desc, NIP_Keyword, NIP_InstructionManu, NIP_Software, Package, Listing_Ready', 'length', 'max' => 20),
            array('Currency, Holiday, Event, Promotion, Lot, QStatus, RCMDPerson, OF1, OF2, Package_Code, Active', 'length', 'max' => 50),
            array('Flup_P, ProductSize', 'length', 'max' => 200),
            array('StockoutDate', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('ProductID, ProductModel, ProductName, ProductDetail, VendorCode, Inventory, Specialty, SizeInch, Sizecm, WeightLB, WeightG, WeighttoCust, FactoryCost, LACost, Packing, PurchaseTotal, SalesTotal, DamagedTotal, AverageCost, OnHand, ReorderPoint, Comment, CreateTime, UpdateTime, Login, Modifier, LAAvgCost, PModel_2, UsedTotal, OnHold, Available, ShipTotal, LentTotal, Currency, Category, Color, SubCategory, Style, Type, Div, SubDiv, NIDNo, Amazon_S, Ebay_S, Class, Rank, OnShipping, TurnaroundTime, TurTimeCoefficient, ReOrder_Qty, ReOrder_Days, OHDayNo, Ivnt_Value, ExceedingNo, AverageProfit, SalesWeek, NIP_Photo, NIP_Desc, NIP_Keyword, NIP_InstructionManu, NIP_Software, Package, Holiday, Event, Promotion, ListingNo, Listing_Ready, Description, Amazon_P, eBayFS, Buy, Offer, Bid, Lot, Lot1_Amazon, Lot2_Amazon, Lot3_Amazon, Lot4_Amazon, QStatus, Purchased, Listing_Des, RCMDPerson, Lot1_Ebay, Lot2_Ebay, Lot3_Ebay, Lot4_Ebay, Flup_P, OF1, OF2, FollowList, Freight_Home, Freight_ByAir, Freight_BySea, Freight_USAF, Freight_ToCus, Amazon_L, Ebay_L, Package_Code, Qty_1Day, Qty_3Day, Qty_1Week, Qty_2Week, Qty_4Week, Qty_Avg_3Day, Qty_Avg_1Week, Qty_Avg_2Week, Qty_Avg_4Week, Qty_Avg_12Week, Q_Diff_1Day, Q_Diff_1Week, StockoutDate, Avg_SalesVolume, TAT_StockUp_D, TAT_Shipping_D, TAT_Offset_D, ItemCoefficient, SeasonCoefficient, AdjustedSalesRate, Profit_C, ProdPackL_cm, ProdPackW_cm, ProdPackH_cm, BoxSizeL_cm, BoxSizeW_cm, BoxSizeH_cm, ProductSize, BoxQuantity, Active', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'ProductID' => 'Product',
            'ProductModel' => 'Product Model',
            'ProductName' => 'Product Name',
            'ProductDetail' => 'Product Detail',
            'VendorCode' => 'Vendor Code',
            'Inventory' => 'Inventory',
            'Specialty' => 'Specialty',
            'SizeInch' => 'Size Inch',
            'Sizecm' => 'Sizecm',
            'WeightLB' => 'Weight Lb',
            'WeightG' => '单品重量(g)',
            'WeighttoCust' => '整箱重量(kg)',
            'FactoryCost' => 'Factory Cost',
            'LACost' => 'Lacost',
            'Packing' => 'Packing',
            'PurchaseTotal' => 'Purchase Total',
            'SalesTotal' => 'Sales Total',
            'DamagedTotal' => 'Damaged Total',
            'AverageCost' => 'Average Cost',
            'OnHand' => 'On Hand',
            'ReorderPoint' => 'Reorder Point',
            'Comment' => 'Comment',
            'CreateTime' => 'Create Time',
            'UpdateTime' => 'Update Time',
            'Login' => 'Login',
            'Modifier' => 'Modifier',
            'LAAvgCost' => 'Laavg Cost',
            'PModel_2' => 'Pmodel 2',
            'UsedTotal' => 'Used Total',
            'OnHold' => 'On Hold',
            'Available' => 'Available',
            'ShipTotal' => 'Ship Total',
            'LentTotal' => 'Lent Total',
            'Currency' => 'Currency',
            'Category' => 'Category',
            'Color' => 'Color',
            'SubCategory' => 'Sub Category',
            'Style' => 'Style',
            'Type' => 'Type',
            'Div' => 'Div',
            'SubDiv' => 'Sub Div',
            'NIDNo' => 'Nidno',
            'Amazon_S' => 'Amazon S',
            'Ebay_S' => 'Ebay S',
            'Class' => 'Class',
            'Rank' => 'Rank',
            'OnShipping' => 'On Shipping',
            'TurnaroundTime' => 'Turnaround Time',
            'TurTimeCoefficient' => 'Tur Time Coefficient',
            'ReOrder_Qty' => 'Re Order Qty',
            'ReOrder_Days' => 'Re Order Days',
            'OHDayNo' => 'Ohday No',
            'Ivnt_Value' => 'Ivnt Value',
            'ExceedingNo' => 'Exceeding No',
            'AverageProfit' => 'Average Profit',
            'SalesWeek' => 'Sales Week',
            'NIP_Photo' => 'Nip Photo',
            'NIP_Desc' => 'Nip Desc',
            'NIP_Keyword' => 'Nip Keyword',
            'NIP_InstructionManu' => 'Nip Instruction Manu',
            'NIP_Software' => 'Nip Software',
            'Package' => 'Package',
            'Holiday' => 'Holiday',
            'Event' => 'Event',
            'Promotion' => 'Promotion',
            'ListingNo' => 'Listing No',
            'Listing_Ready' => 'Listing Ready',
            'Description' => 'Description',
            'Amazon_P' => 'Amazon P',
            'eBayFS' => 'E Bay Fs',
            'Buy' => 'Buy',
            'Offer' => 'Offer',
            'Bid' => 'Bid',
            'Lot' => 'Lot',
            'Lot1_Amazon' => 'Lot1 Amazon',
            'Lot2_Amazon' => 'Lot2 Amazon',
            'Lot3_Amazon' => 'Lot3 Amazon',
            'Lot4_Amazon' => 'Lot4 Amazon',
            'QStatus' => 'Qstatus',
            'Purchased' => 'Purchased',
            'Listing_Des' => 'Listing Des',
            'RCMDPerson' => 'Rcmdperson',
            'Lot1_Ebay' => 'Lot1 Ebay',
            'Lot2_Ebay' => 'Lot2 Ebay',
            'Lot3_Ebay' => 'Lot3 Ebay',
            'Lot4_Ebay' => 'Lot4 Ebay',
            'Flup_P' => 'Flup P',
            'OF1' => 'Of1',
            'OF2' => 'Of2',
            'FollowList' => 'Follow List',
            'Freight_Home' => 'Freight Home',
            'Freight_ByAir' => 'Freight By Air',
            'Freight_BySea' => 'Freight By Sea',
            'Freight_USAF' => 'Freight Usaf',
            'Freight_ToCus' => 'Freight To Cus',
            'Amazon_L' => 'Amazon L',
            'Ebay_L' => 'Ebay L',
            'Package_Code' => 'Package Code',
            'Qty_1Day' => 'Qty 1 Day',
            'Qty_3Day' => 'Qty 3 Day',
            'Qty_1Week' => 'Qty 1 Week',
            'Qty_2Week' => 'Qty 2 Week',
            'Qty_4Week' => 'Qty 4 Week',
            'Qty_Avg_3Day' => 'Qty Avg 3 Day',
            'Qty_Avg_1Week' => 'Qty Avg 1 Week',
            'Qty_Avg_2Week' => 'Qty Avg 2 Week',
            'Qty_Avg_4Week' => 'Qty Avg 4 Week',
            'Qty_Avg_12Week' => 'Qty Avg 12 Week',
            'Q_Diff_1Day' => 'Q Diff 1 Day',
            'Q_Diff_1Week' => 'Q Diff 1 Week',
            'StockoutDate' => 'Stockout Date',
            'Avg_SalesVolume' => 'Avg Sales Volume',
            'TAT_StockUp_D' => 'Tat Stock Up D',
            'TAT_Shipping_D' => 'Tat Shipping D',
            'TAT_Offset_D' => 'Tat Offset D',
            'ItemCoefficient' => 'Item Coefficient',
            'SeasonCoefficient' => 'Season Coefficient',
            'AdjustedSalesRate' => 'Adjusted Sales Rate',
            'Profit_C' => 'Profit C',
            'ProdPackL_cm' => '单品尺寸_长(cm) ',
            'ProdPackW_cm' => '单品尺寸_宽(cm) ',
            'ProdPackH_cm' => '单品尺寸_高(cm)',
            'BoxSizeL_cm' => '整箱尺寸_长(cm)',
            'BoxSizeW_cm' => '整箱尺寸_宽(cm)',
            'BoxSizeH_cm' => '整箱尺寸_高(cm)',
            'ProductSize' => '产品展开尺寸',
            'BoxQuantity' => '整箱产品数量',
            'Active' => 'Active',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('ProductID', $this->ProductID);
        $criteria->compare('ProductModel', $this->ProductModel, true);
        $criteria->compare('ProductName', $this->ProductName, true);
        $criteria->compare('ProductDetail', $this->ProductDetail, true);
        $criteria->compare('VendorCode', $this->VendorCode, true);
        $criteria->compare('Inventory', $this->Inventory, true);
        $criteria->compare('Specialty', $this->Specialty, true);
        $criteria->compare('SizeInch', $this->SizeInch, true);
        $criteria->compare('Sizecm', $this->Sizecm, true);
        $criteria->compare('WeightLB', $this->WeightLB);
        $criteria->compare('WeightG', $this->WeightG);
        $criteria->compare('WeighttoCust', $this->WeighttoCust);
        $criteria->compare('FactoryCost', $this->FactoryCost);
        $criteria->compare('LACost', $this->LACost);
        $criteria->compare('Packing', $this->Packing, true);
        $criteria->compare('PurchaseTotal', $this->PurchaseTotal);
        $criteria->compare('SalesTotal', $this->SalesTotal);
        $criteria->compare('DamagedTotal', $this->DamagedTotal);
        $criteria->compare('AverageCost', $this->AverageCost);
        $criteria->compare('OnHand', $this->OnHand);
        $criteria->compare('ReorderPoint', $this->ReorderPoint);
        $criteria->compare('Comment', $this->Comment, true);
        $criteria->compare('CreateTime', $this->CreateTime, true);
        $criteria->compare('UpdateTime', $this->UpdateTime, true);
        $criteria->compare('Login', $this->Login, true);
        $criteria->compare('Modifier', $this->Modifier, true);
        $criteria->compare('LAAvgCost', $this->LAAvgCost);
        $criteria->compare('PModel_2', $this->PModel_2, true);
        $criteria->compare('UsedTotal', $this->UsedTotal);
        $criteria->compare('OnHold', $this->OnHold);
        $criteria->compare('Available', $this->Available);
        $criteria->compare('ShipTotal', $this->ShipTotal);
        $criteria->compare('LentTotal', $this->LentTotal);
        $criteria->compare('Currency', $this->Currency, true);
        $criteria->compare('Category', $this->Category, true);
        $criteria->compare('Color', $this->Color, true);
        $criteria->compare('SubCategory', $this->SubCategory, true);
        $criteria->compare('Style', $this->Style, true);
        $criteria->compare('Type', $this->Type, true);
        $criteria->compare('Div', $this->Div, true);
        $criteria->compare('SubDiv', $this->SubDiv, true);
        $criteria->compare('NIDNo', $this->NIDNo, true);
        $criteria->compare('Amazon_S', $this->Amazon_S);
        $criteria->compare('Ebay_S', $this->Ebay_S);
        $criteria->compare('Class', $this->Class, true);
        $criteria->compare('Rank', $this->Rank, true);
        $criteria->compare('OnShipping', $this->OnShipping);
        $criteria->compare('TurnaroundTime', $this->TurnaroundTime);
        $criteria->compare('TurTimeCoefficient', $this->TurTimeCoefficient);
        $criteria->compare('ReOrder_Qty', $this->ReOrder_Qty);
        $criteria->compare('ReOrder_Days', $this->ReOrder_Days);
        $criteria->compare('OHDayNo', $this->OHDayNo);
        $criteria->compare('Ivnt_Value', $this->Ivnt_Value);
        $criteria->compare('ExceedingNo', $this->ExceedingNo);
        $criteria->compare('AverageProfit', $this->AverageProfit);
        $criteria->compare('SalesWeek', $this->SalesWeek);
        $criteria->compare('NIP_Photo', $this->NIP_Photo, true);
        $criteria->compare('NIP_Desc', $this->NIP_Desc, true);
        $criteria->compare('NIP_Keyword', $this->NIP_Keyword, true);
        $criteria->compare('NIP_InstructionManu', $this->NIP_InstructionManu, true);
        $criteria->compare('NIP_Software', $this->NIP_Software, true);
        $criteria->compare('Package', $this->Package, true);
        $criteria->compare('Holiday', $this->Holiday, true);
        $criteria->compare('Event', $this->Event, true);
        $criteria->compare('Promotion', $this->Promotion, true);
        $criteria->compare('ListingNo', $this->ListingNo);
        $criteria->compare('Listing_Ready', $this->Listing_Ready, true);
        $criteria->compare('Description', $this->Description, true);
        $criteria->compare('Amazon_P', $this->Amazon_P);
        $criteria->compare('eBayFS', $this->eBayFS);
        $criteria->compare('Buy', $this->Buy);
        $criteria->compare('Offer', $this->Offer);
        $criteria->compare('Bid', $this->Bid);
        $criteria->compare('Lot', $this->Lot, true);
        $criteria->compare('Lot1_Amazon', $this->Lot1_Amazon);
        $criteria->compare('Lot2_Amazon', $this->Lot2_Amazon);
        $criteria->compare('Lot3_Amazon', $this->Lot3_Amazon);
        $criteria->compare('Lot4_Amazon', $this->Lot4_Amazon);
        $criteria->compare('QStatus', $this->QStatus, true);
        $criteria->compare('Purchased', $this->Purchased);
        $criteria->compare('Listing_Des', $this->Listing_Des, true);
        $criteria->compare('RCMDPerson', $this->RCMDPerson, true);
        $criteria->compare('Lot1_Ebay', $this->Lot1_Ebay);
        $criteria->compare('Lot2_Ebay', $this->Lot2_Ebay);
        $criteria->compare('Lot3_Ebay', $this->Lot3_Ebay);
        $criteria->compare('Lot4_Ebay', $this->Lot4_Ebay);
        $criteria->compare('Flup_P', $this->Flup_P, true);
        $criteria->compare('OF1', $this->OF1, true);
        $criteria->compare('OF2', $this->OF2, true);
        $criteria->compare('FollowList', $this->FollowList, true);
        $criteria->compare('Freight_Home', $this->Freight_Home);
        $criteria->compare('Freight_ByAir', $this->Freight_ByAir);
        $criteria->compare('Freight_BySea', $this->Freight_BySea);
        $criteria->compare('Freight_USAF', $this->Freight_USAF);
        $criteria->compare('Freight_ToCus', $this->Freight_ToCus);
        $criteria->compare('Amazon_L', $this->Amazon_L);
        $criteria->compare('Ebay_L', $this->Ebay_L);
        $criteria->compare('Package_Code', $this->Package_Code, true);
        $criteria->compare('Qty_1Day', $this->Qty_1Day);
        $criteria->compare('Qty_3Day', $this->Qty_3Day);
        $criteria->compare('Qty_1Week', $this->Qty_1Week);
        $criteria->compare('Qty_2Week', $this->Qty_2Week);
        $criteria->compare('Qty_4Week', $this->Qty_4Week);
        $criteria->compare('Qty_Avg_3Day', $this->Qty_Avg_3Day);
        $criteria->compare('Qty_Avg_1Week', $this->Qty_Avg_1Week);
        $criteria->compare('Qty_Avg_2Week', $this->Qty_Avg_2Week);
        $criteria->compare('Qty_Avg_4Week', $this->Qty_Avg_4Week);
        $criteria->compare('Qty_Avg_12Week', $this->Qty_Avg_12Week);
        $criteria->compare('Q_Diff_1Day', $this->Q_Diff_1Day);
        $criteria->compare('Q_Diff_1Week', $this->Q_Diff_1Week);
        $criteria->compare('StockoutDate', $this->StockoutDate, true);
        $criteria->compare('Avg_SalesVolume', $this->Avg_SalesVolume);
        $criteria->compare('TAT_StockUp_D', $this->TAT_StockUp_D);
        $criteria->compare('TAT_Shipping_D', $this->TAT_Shipping_D);
        $criteria->compare('TAT_Offset_D', $this->TAT_Offset_D);
        $criteria->compare('ItemCoefficient', $this->ItemCoefficient);
        $criteria->compare('SeasonCoefficient', $this->SeasonCoefficient);
        $criteria->compare('AdjustedSalesRate', $this->AdjustedSalesRate);
        $criteria->compare('Profit_C', $this->Profit_C);
        $criteria->compare('ProdPackL_cm', $this->ProdPackL_cm);
        $criteria->compare('ProdPackW_cm', $this->ProdPackW_cm);
        $criteria->compare('ProdPackH_cm', $this->ProdPackH_cm);
        $criteria->compare('BoxSizeL_cm', $this->BoxSizeL_cm);
        $criteria->compare('BoxSizeW_cm', $this->BoxSizeW_cm);
        $criteria->compare('BoxSizeH_cm', $this->BoxSizeH_cm);
        $criteria->compare('ProductSize', $this->ProductSize, true);
        $criteria->compare('BoxQuantity', $this->BoxQuantity);
        $criteria->compare('Active', $this->Active, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }
    
    protected function beforeSave() {
        if (parent::beforeSave()) {
            if ($this->isNewRecord) {
                $this->Type = 'MX';
                $this->Inventory = 'Yes';
                $this->Div = 'O2C';
                $this->SubDiv = 'CA';
                $this->Class = 'C1';
                $this->Currency = 'USD';
                $this->Login = $this->Modifier = Yii::app()->user->name;
                $this->CreateTime = $this->UpdateTime = date('Ymd H:i');
                $this->ProductModel = Helper::getProductModel();
                $this->ProductName = $this->SubCategory.'_'.$this->ProductModel;
                if(!$this->NIDNo){
                    $this->NIDNo = Helper::getNIDNo();
                }                
            }else{
                $this->UpdateTime = date('Ymd H:i');
                $this->Modifier = Yii::app()->user->name;
            }
        }
        return true;
    }
    
    protected function afterSave() {
        if(parent::afterSave()){
            Helper::updateAvgCost($this->ProductID);
        }
    }

}